package com.xr.wage.change;

import com.xr.common.CommUtil;
import com.bstek.dorado.common.*;
import com.bstek.dorado.data.*;
import com.bstek.dorado.data.db.DBStatement;
import com.bstek.dorado.utils.variant.VariantSet;
import com.bstek.dorado.view.*;
import com.bstek.dorado.view.data.*;
import com.bstek.dorado.view.control.*;

/**
 * onOffCwEmpListViewModel
 */
public class onOffCwEmpListViewModel extends DefaultViewModel {
	
  public void create(ParameterSet parameters, ParameterSet outParameters)
      throws Exception { 
		DBStatement dbs = new DBStatement();
		Dataset dsCL = getDataset("datasetChangeList");
		
		CommUtil.dbsUpdateData(dbs, dsCL, "wa_change", "WA_CHANGE_ID");
		dbs.setSql("begin pck_cw.getCwMonth("+dsCL.getString("WAGE_MONTH")+","+dsCL.getString("WA_CHANGE_ID")+"); end;");
		dbs.execute();
		dbs.close(); 
   // super.doUpdateData(parameters, outParameters);
  }
  public void saveDetail(ParameterSet parameters, ParameterSet outParameters)
  throws Exception { 
		DBStatement dbs = new DBStatement();
		Dataset dsCL = getDataset("datasetChangeEmpDetail");
 
	    CommUtil.dbsUpdateData(dbs, dsCL, "wa_change_emp", "change_emp_id");
	 
		dbs.close();
  }
  public void dr(ParameterSet parameters, ParameterSet outParameters)
  throws Exception { 
		DBStatement dbs = new DBStatement();
		Dataset dsCL = getDataset("datasetChangeList");
		dbs.setSql("delete from wa_change_emp where wa_change_id="+dsCL.getString("wa_change_id"));
		dbs.execute();
		dbs.setSql("delete from wa_change where wa_change_id="+dsCL.getString("wa_change_id"));
		dbs.execute();
		dbs.close();
  }
  
  public void sendCheck(ParameterSet parameters, ParameterSet outParameters)
  throws Exception { 
		DBStatement dbs = new DBStatement();
		Dataset dsCL = getDataset("datasetChangeList");
		dbs.setSql("select distinct ude.man_employee_id MAN_EMPLOYEE_ID from wa_change_emp ce,rt_user_deal_emp ude where ce.onoff_station_id=ude.emp_onoff_station_id and ude.BUSINESS_TYPE=10 and ce.wa_change_id="+dsCL.getString("wa_change_id"));
		java.util.List list= dbs.queryForList();
		for(int i=0;i<list.size();i++){
			VariantSet vs =(VariantSet)list.get(i);
			dbs.setSql("begin pck_todo.todoAtoB(55,"+dsCL.getString("wa_change_id")+","+CommUtil.getEmployeeId()+","+vs.getString("MAN_EMPLOYEE_ID")+"); end;");
			dbs.execute();
			
		}
		dbs.setSql("update wa_change set status=1 where wa_change_id="+dsCL.getString("wa_change_id"));
		dbs.execute();
		dbs.setSql("update wa_change_emp set status=1 where wa_change_id="+dsCL.getString("wa_change_id"));
		dbs.execute();
		dbs.close();
  }
  
  public void sureAgress(ParameterSet parameters, ParameterSet outParameters)
  throws Exception { 
		DBStatement dbs = new DBStatement();
		Dataset dsCL = getDataset("datasetChangeList");
		Dataset dsCed = getDataset("datasetChangeEmpDetail");
		
		dsCL.setValue("STATUS", "3");
	    CommUtil.dbsUpdateData(dbs, dsCL, "wa_change", "wa_change_id");
	    
	    dsCed.moveFirst();
	    while(!dsCed.isLast()){
	    	dsCed.setValue("STATUS", "3");
	    	dsCed.moveNext();
	    }
	    
	    CommUtil.dbsUpdateData(dbs, dsCed, "wa_change_emp", "change_emp_id");
	    
		dbs.setSql("begin pck_todo.todoFinish(55,"+CommUtil.getEmployeeId()+","+dsCL.getString("wa_change_id")+"); end;");
		dbs.execute();
		dbs.close();
  }
}
